package org.mat.ipaas.ucenter.service.api.system;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.mat.framework.lang.dto.MatApiResponse;
import org.mat.ipaas.ucenter.service.dto.system.entity.SysCategoryDTO;
import org.mat.ipaas.ucenter.service.dto.system.model.TreeSelectModelDTO;
import org.mat.ipaas.ucenter.service.dto.system.vo.DictModelDTO;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.cloud.openfeign.SpringQueryMap;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 分类字典
 */

@FeignClient(name = "mat-ipaas-ucenter-service", contextId = "sys-category-rest-api")
public interface SysCategoryRestAPI {

    /**
     * 分页列表查询
     *
     * @param sysCategoryDTO
     * @param pageNo
     * @param pageSize
     * @return
     */
    @GetMapping(value = "/sys/category/rootList")
    MatApiResponse<Page<SysCategoryDTO>> queryPageList(@SpringQueryMap SysCategoryDTO sysCategoryDTO,
                                                       @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                       @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize);

    @GetMapping(value = "/sys/category/childList")
    MatApiResponse<List<SysCategoryDTO>> queryPageList(@SpringQueryMap SysCategoryDTO sysCategoryDTO);


    /**
     * 添加
     *
     * @param sysCategoryDTO
     * @return
     */
    @PostMapping(value = "/sys/category/add")
    MatApiResponse<SysCategoryDTO> add(@RequestBody SysCategoryDTO sysCategoryDTO);

    /**
     * 编辑
     *
     * @param sysCategoryDTO
     * @return
     */
    @RequestMapping(value = "/sys/category/edit", method = {RequestMethod.POST})
    MatApiResponse<SysCategoryDTO> edit(@RequestBody SysCategoryDTO sysCategoryDTO);

    /**
     * 通过id删除
     *
     * @param id
     * @return
     */
    @DeleteMapping(value = "/sys/category/delete")
    MatApiResponse<SysCategoryDTO> delete(@RequestParam(name = "id", required = true) String id);

    /**
     * 批量删除
     *
     * @param ids
     * @return
     */
    @DeleteMapping(value = "/sys/category/deleteBatch")
    MatApiResponse<SysCategoryDTO> deleteBatch(@RequestParam(name = "ids", required = true) String ids);

    /**
     * 通过id查询
     *
     * @param id
     * @return
     */
    @GetMapping(value = "/sys/category/queryById")
    MatApiResponse<SysCategoryDTO> queryById(@RequestParam(name = "id", required = true) String id);

    /**
     * 导出excel
     *
     * 
     */
    @RequestMapping(value = "/sys/category/exportXls")
    ModelAndView exportXls( SysCategoryDTO sysCategoryDTO);

    /**
     * 通过excel导入数据
     *
     * 
     * 
     * @return
     */
    @RequestMapping(value = "/sys/category/importExcel", method = RequestMethod.POST)
    MatApiResponse<?> importExcel( ) throws IOException;


    /**
     * 加载单个数据 用于回显
     */
    @RequestMapping(value = "/sys/category/loadOne", method = RequestMethod.GET)
    MatApiResponse<SysCategoryDTO> loadOne(@RequestParam(name = "field") String field, @RequestParam(name = "val") String val);

    /**
     * 加载节点的子数据
     */
    @RequestMapping(value = "/sys/category/loadTreeChildren", method = RequestMethod.GET)
    MatApiResponse<List<TreeSelectModelDTO>> loadTreeChildren(@RequestParam(name = "pid") String pid);

    /**
     * 加载一级节点/如果是同步 则所有数据
     */
    @RequestMapping(value = "/sys/category/loadTreeRoot", method = RequestMethod.GET)
    MatApiResponse<List<TreeSelectModelDTO>> loadTreeRoot(@RequestParam(name = "async") Boolean async, @RequestParam(name = "pcode") String pcode);

    /**
     * 校验编码
     *
     * @param pid
     * @param code
     * @return
     */
    @GetMapping(value = "/sys/category/checkCode")
    MatApiResponse<?> checkCode(@RequestParam(name = "pid", required = false) String pid, @RequestParam(name = "code", required = false) String code);


    /**
     * 分类字典树控件 加载节点
     *
     * @param pid
     * @param pcode
     * @param condition
     * @return
     */
    @RequestMapping(value = "/sys/category/loadTreeData", method = RequestMethod.GET)
    MatApiResponse<List<TreeSelectModelDTO>> loadDict(@RequestParam(name = "pid", required = false) String pid, @RequestParam(name = "pcode", required = false) String pcode, @RequestParam(name = "condition", required = false) String condition);

    /**
     * 分类字典控件数据回显[表单页面]
     *
     * @param ids
     * @param delNotExist 是否移除不存在的项，默认为true，设为false如果某个key不存在数据库中，则直接返回key本身
     * @return
     */
    @RequestMapping(value = "/sys/category/loadDictItem", method = RequestMethod.GET)
    MatApiResponse<List<String>> loadDictItem(@RequestParam(name = "ids") String ids, @RequestParam(name = "delNotExist", required = false, defaultValue = "true") boolean delNotExist);

    /**
     * [列表页面]加载分类字典数据 用于值的替换
     *
     * @param code
     * @return
     */
    @RequestMapping(value = "/sys/category/loadAllData", method = RequestMethod.GET)
    MatApiResponse<List<DictModelDTO>> loadAllData(@RequestParam(name = "code", required = true) String code);

    /**
     * 根据父级id批量查询子节点
     *
     * @param parentIds
     * @return
     */
    @GetMapping("/sys/category/getChildListBatch")
    MatApiResponse getChildListBatch(@RequestParam("parentIds") String parentIds);


}
